package com.genshang.restaurant.controller;


import com.genshang.restaurant.result.ResultBody;
import com.genshang.restaurant.service.IAccumulatelisttableService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Alex
 * @since 2020-09-25
 */
@RestController
@RequestMapping("/accumulatelisttable")
public class AccumulatelisttableController {
    Logger logger = LoggerFactory.getLogger(AccumulatelisttableController.class);

    @Autowired
    private IAccumulatelisttableService accumulatelisttableService;

    /**
     * 3. 获取用户有赞积分
     *
     * @param phone
     * @return
     */
    @GetMapping("/getYouZanAccumulate")
    public ResultBody getYouZanAccumulate(String phone) {
        logger.info("获取用户信息 openId = " + phone);
        return accumulatelisttableService.getYouZanAccumulate(phone);
    }


    /**
     * 4. 修改有赞积分
     *
     * @param phone
     * @param youZanAccumulate
     * @param operateType      "1" 新增，"0"减少
     * @return
     */
    @PostMapping("/updateYouZanAccumulate")
    public ResultBody updateYouZanAccumulate(String phone, String youZanAccumulate, String operateType) {
        return accumulatelisttableService.updateYouZanAccumulate(phone, youZanAccumulate, operateType);
    }


    @PostMapping("/exchange")
    public ResultBody exchange(String shopId, String accumulate, String phone,String goodsId) {
        return accumulatelisttableService.exchange(shopId, accumulate, phone, goodsId);
    }
}
